const fileApi = require ('./api/file');
const bodyParser = require ('body-parser');
const express = require ('express');
const app = express ();
app.all ('*', function (req, res, next) {
  // allow all domain
  res.header ('Access-Control-Allow-Origin', '*');
  // allowed header type
  res.header ('Access-Control-Allow-Headers', 'content-type');
  // allowed request method
  res.header ('Access-Control-Allow-Methods', 'DELETE,PUT,POST,GET,OPTIONS');
  if (req.method.toLowerCase () == 'options') res.sendStatus (200);
  else next ();
});
app.use (bodyParser.json ());
app.use (bodyParser.urlencoded ({extended: false}));

// router of backend
app.use ('/api/file', fileApi);
// listen port 3000
app.listen (3000);
console.log ('success listen at port:3000......');
